<template>
	<view>

		<u-form label-width="150rpx" style="padding: 20rpx 20rpx 20rpx 50rpx;">
			<u-form-item label="奶量">
				<u-radio-group v-model="radio" >
					<u-radio 
					style="padding: 30rpx 60rpx 30rpx 60rpx;"  
					v-for="(item, index) in list" 
					:key="index" 
					:name="item.name" 
					@change="radioChange" >
						<span style="font-size:45rpx" >{{ item.name }}</span>
					</u-radio>
				</u-radio-group>
			</u-form-item>
			<u-form-item label="时间" @click="cShow">			
				<u-input v-model="time" @tap="show = true" disabled/>
				<u-picker v-model="show" mode="time" :default-time="time" :params="params" @confirm="confirmTime"></u-picker>
			</u-form-item>

		</u-form>
		<u-row gutter="16" style="padding: 10rpx 10rpx 60rpx 10rpx;" >
			<u-col span="2">
				<span>&nbsp;</span>
			</u-col>
			<u-col span="3">
				<u-button type="error" size="medium" @click="openDel">删除</u-button>
			</u-col>
			<u-col span="2">
				<span>&nbsp;</span>
			</u-col>
			<u-col span="3">
				<u-button type="primary" size="medium" @click="register">保存</u-button>
			</u-col>
			<u-col span="2">
				<span>&nbsp;</span>
			</u-col>
		</u-row>
		<view>
			<u-popup v-model="showPopup" mode="bottom">
				<u-gap height="30"></u-gap>
				<u-alert-tips show-icon type="warning" title="警告" description="您确定要删除本条数据吗？"></u-alert-tips>
				<u-row gutter="16" >
					<u-col span="2">
						<span>&nbsp;</span>
					</u-col>
					<u-col span="3">
						<u-button type="error" size="medium" @click="del">删除</u-button>
					</u-col>
					<u-col span="2">
						<span>&nbsp;</span>
					</u-col>
					<u-col span="3">
						<u-button type="info" size="medium" @click="showPopup = false">取消</u-button>
					</u-col>
					<u-col span="2">
						<span>&nbsp;</span>
					</u-col>
					<u-gap height="180"></u-gap>
				</u-row>
			</u-popup>
		</view>

		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id : 0,
				status : 1,
				time: "",
				radio: '30',
				list: [
					{
						name: '30',
						disabled: false
					},
					{
						name: '60',
						disabled: false
					},
					{
						name: '90',
						disabled: false
					},
					{
						name: '120',
						disabled: false
					}
				],
				show: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true,
					timestamp: true,
				},
				time: this.$u.timeFormat(new Date, "yyyy-mm-dd hh:MM:ss"),
				showPopup: false
			}
		},
		onLoad(option) {
			this.id = option.id;
			this.time = this.$u.timeFormat(option.createTime, "yyyy-mm-dd hh:MM:ss");
			this.radio = option.num;
		},
		methods:{
			radioChange(e){
				console.log(e);
			},		
			// 修改日期
			confirmTime(val){
				this.time = this.$u.timeFormat(val.timestamp, "yyyy-mm-dd hh:MM:ss");
			},
			// 注册
			register(){
				this.$u.post('/milk/milkrecord/update', {
						id: this.id,
						num: this.radio,
						status: this.status,
						createTime: this.time
					}).then(data => {
						if (data && data.code === 0) {
							this.$refs.uToast.show({title: '保存成功',type: 'success',url: '/pages/total/chart', isTab : true, duration: 400});
							setTimeout(this.canel, 1000);
						} else {
							this.$refs.uToast.show({title: data.msg, type: 'error',});
						}
					}).catch((e) => {
						this.$refs.uToast.show({title: "手机好累哦^_^", type: 'error',});
					});
			},
			// 重置数据
			dataReset(){
				this.time = this.$u.timeFormat(new Date, "yyyy-mm-dd hh:MM:ss");
				this.radio = '30';
			},
			// 显示提示框
			openDel(){
				this.showPopup = true;
			},
			// 删除记录
			del(){
				this.status = -1;
				this.register();
			},
		}
	}
</script>